package cn.howxu.yichen_ovo.extension.jade;

import cn.howxu.yichen_ovo.Res;
import cn.howxu.yichen_ovo.common.entity.DollEntity;
import cn.howxu.yichen_ovo.registry.DollRegistryEvent;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.registries.ForgeRegistries;
import snownee.jade.api.EntityAccessor;
import snownee.jade.api.IEntityComponentProvider;
import snownee.jade.api.ITooltip;
import snownee.jade.api.config.IPluginConfig;

public enum EntityComponentProvider implements IEntityComponentProvider {
    INSTANCE;

    public static final ResourceLocation ID = Res.rl("doll_entity");

    @Override
    public void appendTooltip(ITooltip tooltip, EntityAccessor accessor, IPluginConfig pluginConfig) {
        if (!(accessor.getEntity() instanceof DollEntity dollEntity)) {
            return;
        }
        Block block = dollEntity.getDisplayBlockState().getBlock();
        ResourceLocation key = ForgeRegistries.BLOCKS.getKey(block);
        if (key == null) {
            return;
        }
        ChatFormatting formatting;
        int size = DollRegistryEvent.Jade_Plugin_tips.get(ForgeRegistries.BLOCKS.getKey(block).getPath()).size() + 1;
        int level = DollRegistryEvent.Jade_Plugin_levels.get(ForgeRegistries.BLOCKS.getKey(block).getPath());
        switch (level){
            case 1 -> {
                formatting = ChatFormatting.GREEN;
            }
            case 2 -> {
                formatting = ChatFormatting.BLUE;
            }
            case 3 -> {
                formatting = ChatFormatting.GOLD;
            }
            default -> {
                formatting = ChatFormatting.WHITE;
            }
        }
        for (int i = 1;i < size;i++){
            tooltip.add(Component.translatable("tooltip.yichenovo.doll." + ForgeRegistries.BLOCKS.getKey(block).getPath() + ".tip" + i).withStyle(formatting));
        }
    }

    @Override
    public ResourceLocation getUid() {
        return ID;
    }
}
